package com.czg.app;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import com.czg.jsonschema2lombokpojo.JsonSchema2LombokPojo;
import com.czg.jsonschema2lombokpojo.SourceType;
import com.czg.jsonschema2lombokpojo.config.GenerationConfig;
import com.czg.jsonschema2lombokpojo.util.JavaVersion;
import com.czg.jsonschema2lombokpojo.util.URLUtil;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;


public class ApplicationTools {

    protected Shell shell;
    private Text textAccessorsPrefix;
    private Text textOutPutTargetDirectory;
    private Text textTargetPackage;
    private Text textClassNamePrefix;
    private Text textClassNameSuffix;
    private Text textSourceFile;
    private Button button_Create;
    private Button button_Close;
    private Button btnJsonschema;
    private Button btnJson;
    private Button btnYamlschema;
    private Button btnYaml;
    private Button btnIsEnumInSubPackage;
    private Button btnIsEnumTypeAddSuffix;
    private Button btnIsUseTitleAsClassname;
    private Combo comboCustomTimePattern;
    private Combo comboCustomDateTimePattern;
    private Button btnIsFormatDateTimes;
    private Button btnIsFormatDates;
    private Button btnIsIncludeAdditionalProperties;
    private Combo comboCustomDatePattern;
    private Button btnIsInitializeCollections;
    private Button btnIsSerializable;
    private Button btnIsIncludeValidationAnnotations;
    private Button btnIsUseFloat;
    private Button btnIsUseDoubleNumbers;
    private Button btnIsUseBigDecimals;
    private Button btnIsUseInteger;
    private Button btnIsUseLongIntegers;
    private Button btnIsUseBigIntegers;
    private Button btnAccessorsFluentValue;
    private Button btnIsIncludeNoArgsConstructor;
    private Button btnIsIncludeAllArgsConstructor;
    private Button btnIsIncludeBuilder;
    private Button btnIsIncludeAccessors;
    private Button btnIsIncludeEqualsAndHashCode;
    private Button buttonRestoreDefaults;
    private Button btnAccessorsChainValue;
    private Label lblAccessorsprefixGetter;
    private Button btnIsEnumIncludeGetter;
    private Button btnIsEnumIncludeAllArgsConstructor;
    private Button btnIsIncludeFieldNameConstants;

    /**
     * Launch the application.
     *
     * @param args
     */
    public static void main(String[] args) {
        String javaVersion = System.getProperty("java.version");
        System.out.println("当前JRE版本: " + javaVersion);
        if (javaVersion.startsWith("1.8")) {
            System.out.println("支持Java 8特性");
        } else if (javaVersion.startsWith("11")) {
            System.out.println("支持Java 11特性");
        } else if (javaVersion.startsWith("14")) {
            System.out.println("支持Java 14特性");
        }
        try {
            ApplicationTools window = new ApplicationTools();
            window.open();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Open the window.
     */
    public void open() {
        Display display = Display.getDefault();
        createContents();
        loadLastUserConfig();
        shell.open();
        shell.layout();
        shell.setMaximized(false);
        shell.setSize(new Point(710, 700));
        DockUtil.centerScreen(shell);
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
    }


    /**
     * Create contents of the window.
     */
    protected void createContents() {
        shell = new Shell(SWT.DIALOG_TRIM);
        shell.setSize(1243, 440);
        shell.setText("开发辅助工具");


        textOutPutTargetDirectory = new Text(shell, SWT.BORDER);
        textOutPutTargetDirectory.setBounds(157, 582, 465, 23);

        Label lblNewLabel = new Label(shell, SWT.NONE);
        lblNewLabel.setBounds(10, 582, 141, 17);
        lblNewLabel.setText("生成源代码保存的文件夹");

        Button btnSelectOutPutTargetDirectory = new Button(shell, SWT.NONE);
        btnSelectOutPutTargetDirectory.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                selectOutPutTargetDirectory();
            }
        });
        btnSelectOutPutTargetDirectory.setBounds(624, 580, 35, 27);
        btnSelectOutPutTargetDirectory.setText("...");

        Label lblpackage = new Label(shell, SWT.NONE);
        lblpackage.setBounds(10, 98, 102, 17);
        lblpackage.setText("生成Java的包名称");

        textTargetPackage = new Text(shell, SWT.BORDER);
        textTargetPackage.setBounds(118, 95, 394, 23);

        Group grpJsonschemaintegerjava_2 = new Group(shell, SWT.NONE);
        grpJsonschemaintegerjava_2.setText("被转换的文档类型");
        grpJsonschemaintegerjava_2.setBounds(10, 10, 439, 50);

        btnJsonschema = new Button(grpJsonschemaintegerjava_2, SWT.RADIO);
        btnJsonschema.setSelection(true);
        btnJsonschema.setText("JsonSchema");
        btnJsonschema.setBounds(10, 22, 97, 17);

        btnJson = new Button(grpJsonschemaintegerjava_2, SWT.RADIO);
        btnJson.setText("JSON");
        btnJson.setBounds(119, 22, 53, 17);

        btnYamlschema = new Button(grpJsonschemaintegerjava_2, SWT.RADIO);
        btnYamlschema.setText("YamlSchema");
        btnYamlschema.setBounds(181, 22, 97, 17);

        btnYaml = new Button(grpJsonschemaintegerjava_2, SWT.RADIO);
        btnYaml.setBounds(284, 22, 53, 17);
        btnYaml.setText("Yaml");

        TabFolder tabFolder = new TabFolder(shell, SWT.NONE);
        tabFolder.setBounds(10, 127, 674, 449);

        TabItem tabItem = new TabItem(tabFolder, SWT.NONE);
        tabItem.setText("类配置");

        Composite composite = new Composite(tabFolder, SWT.NONE);
        tabItem.setControl(composite);

        btnIsIncludeEqualsAndHashCode = new Button(composite, SWT.CHECK);
        btnIsIncludeEqualsAndHashCode.setSelection(true);
        btnIsIncludeEqualsAndHashCode.setBounds(10, 88, 678, 17);
        btnIsIncludeEqualsAndHashCode.setToolTipText("默认情况下，它会使用类中所有非静态、非瞬态的字段来生成这些方法。用户可以通过指定exclude参数来排除某些字段，或者使用of参数来仅包含特定的字段。此外，@EqualsAndHashCode(callSuper = true)参数可以在子类中使用，以包含父类的成员变量‌");
        btnIsIncludeEqualsAndHashCode.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
            }
        });
        btnIsIncludeEqualsAndHashCode.setText("类是否包含EqualsAndHashCode注解；注解用于简化Java类中equals和hashCode方法的实现。");

        btnIsIncludeNoArgsConstructor = new Button(composite, SWT.CHECK);
        btnIsIncludeNoArgsConstructor.setSelection(true);
        btnIsIncludeNoArgsConstructor.setBounds(10, 111, 438, 17);
        btnIsIncludeNoArgsConstructor.setText("类是否包含NoArgsConstructor注解；为类生成一个无参构造函数");

        btnIsIncludeAllArgsConstructor = new Button(composite, SWT.CHECK);
        btnIsIncludeAllArgsConstructor.setSelection(true);
        btnIsIncludeAllArgsConstructor.setBounds(10, 134, 475, 17);
        btnIsIncludeAllArgsConstructor.setText("类是否包含AllArgsConstructor注解；自动生成一个包含所有类字段参数的构造函数");

        btnIsIncludeBuilder = new Button(composite, SWT.CHECK);
        btnIsIncludeBuilder.setSelection(true);
        btnIsIncludeBuilder.setBounds(10, 157, 636, 17);
        btnIsIncludeBuilder.setText("类是否包含Builder注解；自动生成一个内部 Builder 类，以及对应的构建方法，从而简化代码的编写。");

        btnIsIncludeAccessors = new Button(composite, SWT.CHECK);
        btnIsIncludeAccessors.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                setIncludeAccessorsEnabled();
            }
        });
        btnIsIncludeAccessors.setBounds(10, 205, 567, 17);
        btnIsIncludeAccessors.setText("类是否包含Accessors注解；用于自动生成 getter 和 setter 方法，从而简化代码的编写。");

        btnAccessorsFluentValue = new Button(composite, SWT.CHECK);
        btnAccessorsFluentValue.setEnabled(false);
        btnAccessorsFluentValue.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
            }
        });
        btnAccessorsFluentValue.setBounds(10, 228, 648, 17);
        btnAccessorsFluentValue.setText("Accessors注解的fluent属性值：如果设置为 true，生成的 getter 方法会移除 get 前缀，setter 方法移除 set 前缀");

        btnAccessorsChainValue = new Button(composite, SWT.CHECK);
        btnAccessorsChainValue.setEnabled(false);
        btnAccessorsChainValue.setBounds(10, 251, 648, 17);
        btnAccessorsChainValue.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
            }
        });
        btnAccessorsChainValue.setText("Accessors注解的chain属性值：如果设置为 true，生成的 setter 方法会返回当前对象，支持方法链调用。");

        lblAccessorsprefixGetter = new Label(composite, SWT.NONE);
        lblAccessorsprefixGetter.setEnabled(false);
        lblAccessorsprefixGetter.setBounds(10, 274, 438, 17);
        lblAccessorsprefixGetter.setText("Accessors注解的prefix属性值：为生成的 getter 和 setter 方法添加指定前缀。");

        textAccessorsPrefix = new Text(composite, SWT.BORDER);
        textAccessorsPrefix.setEnabled(false);
        textAccessorsPrefix.setBounds(10, 297, 260, 23);

        Label lblAccessorsprefixGetter_1 = new Label(composite, SWT.NONE);
        lblAccessorsprefixGetter_1.setBounds(10, 36, 58, 17);
        lblAccessorsprefixGetter_1.setText("类名前缀");

        textClassNamePrefix = new Text(composite, SWT.BORDER);
        textClassNamePrefix.setBounds(67, 33, 260, 23);

        Label lblAccessorsprefixGetter_1_1 = new Label(composite, SWT.NONE);
        lblAccessorsprefixGetter_1_1.setBounds(10, 65, 58, 17);
        lblAccessorsprefixGetter_1_1.setText("类名后缀");

        textClassNameSuffix = new Text(composite, SWT.BORDER);
        textClassNameSuffix.setBounds(67, 62, 260, 23);

        btnIsEnumTypeAddSuffix = new Button(composite, SWT.CHECK);
        btnIsEnumTypeAddSuffix.setBounds(10, 374, 229, 17);
        btnIsEnumTypeAddSuffix.setText("枚举类型添加enum后缀");

        btnIsEnumInSubPackage = new Button(composite, SWT.CHECK);
        btnIsEnumInSubPackage.setSelection(true);
        btnIsEnumInSubPackage.setBounds(10, 397, 280, 17);
        btnIsEnumInSubPackage.setText("枚举类型是否放在enum子包中");

        btnIsUseTitleAsClassname = new Button(composite, SWT.CHECK);
        btnIsUseTitleAsClassname.setBounds(10, 10, 280, 17);
        btnIsUseTitleAsClassname.setText("是否使用“title”属性值作为对象schema的类名。");

        btnIsEnumIncludeGetter = new Button(composite, SWT.CHECK);
        btnIsEnumIncludeGetter.setSelection(true);
        btnIsEnumIncludeGetter.setText("枚举类是否包含Getter注解；自动生成一个getter方法");
        btnIsEnumIncludeGetter.setBounds(10, 326, 342, 17);

        btnIsEnumIncludeAllArgsConstructor = new Button(composite, SWT.CHECK);
        btnIsEnumIncludeAllArgsConstructor.setText("枚举类是否包含AllArgsConstructor注解；自动生成一个包含所有类字段参数的构造函数");
        btnIsEnumIncludeAllArgsConstructor.setSelection(true);
        btnIsEnumIncludeAllArgsConstructor.setBounds(10, 349, 555, 17);

        btnIsIncludeFieldNameConstants = new Button(composite, SWT.CHECK);
        btnIsIncludeFieldNameConstants.setText("类是否包含FieldNameConstants注解注解；自动生成字段名称常量。");
        btnIsIncludeFieldNameConstants.setSelection(true);
        btnIsIncludeFieldNameConstants.setBounds(10, 180, 636, 17);

        TabItem tabItem_1 = new TabItem(tabFolder, SWT.NONE);
        tabItem_1.setText("属性配置");

        Composite composite_1 = new Composite(tabFolder, SWT.NONE);
        tabItem_1.setControl(composite_1);

        btnIsSerializable = new Button(composite_1, SWT.CHECK);
        btnIsSerializable.setSelection(true);
        btnIsSerializable.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
            }
        });
        btnIsSerializable.setBounds(11, 10, 300, 17);
        btnIsSerializable.setText("是否允许序列化");

        btnIsInitializeCollections = new Button(composite_1, SWT.CHECK);
        btnIsInitializeCollections.setBounds(10, 33, 300, 17);
        btnIsInitializeCollections.setText("是否初始化集合");

        Group grpJsonschemaintegerjava = new Group(composite_1, SWT.NONE);
        grpJsonschemaintegerjava.setBounds(10, 56, 308, 98);
        grpJsonschemaintegerjava.setText("JSONschema类型‘integer’，使用java类型");

        btnIsUseInteger = new Button(grpJsonschemaintegerjava, SWT.RADIO);
        btnIsUseInteger.setSelection(true);
        btnIsUseInteger.setBounds(10, 22, 179, 17);
        btnIsUseInteger.setText("java.lang.Integer(默认)");

        btnIsUseLongIntegers = new Button(grpJsonschemaintegerjava, SWT.RADIO);
        btnIsUseLongIntegers.setText("java.lang.Long");
        btnIsUseLongIntegers.setBounds(10, 46, 179, 17);

        btnIsUseBigIntegers = new Button(grpJsonschemaintegerjava, SWT.RADIO);
        btnIsUseBigIntegers.setText("java.math.BigInteger");
        btnIsUseBigIntegers.setBounds(10, 69, 211, 17);

        Group grpJsonschemaintegerjava_1 = new Group(composite_1, SWT.NONE);
        grpJsonschemaintegerjava_1.setBounds(354, 56, 308, 98);
        grpJsonschemaintegerjava_1.setText("JSONschema类型‘number’，使用java类型");

        btnIsUseFloat = new Button(grpJsonschemaintegerjava_1, SWT.RADIO);
        btnIsUseFloat.setSelection(true);
        btnIsUseFloat.setBounds(10, 22, 233, 17);
        btnIsUseFloat.setText("java.lang.Float(默认)");

        btnIsUseDoubleNumbers = new Button(grpJsonschemaintegerjava_1, SWT.RADIO);
        btnIsUseDoubleNumbers.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
            }
        });
        btnIsUseDoubleNumbers.setText("java.lang.Double");
        btnIsUseDoubleNumbers.setBounds(10, 46, 242, 17);

        btnIsUseBigDecimals = new Button(grpJsonschemaintegerjava_1, SWT.RADIO);
        btnIsUseBigDecimals.setText("java.math.BigDecimal");
        btnIsUseBigDecimals.setBounds(10, 69, 242, 17);

        btnIsIncludeValidationAnnotations = new Button(composite_1, SWT.CHECK);
        btnIsIncludeValidationAnnotations.setSelection(true);
        btnIsIncludeValidationAnnotations.setBounds(11, 160, 331, 17);
        btnIsIncludeValidationAnnotations.setText("是否生成合法性验证规则注解");

        btnIsIncludeAdditionalProperties = new Button(composite_1, SWT.CHECK);
        btnIsIncludeAdditionalProperties.setBounds(11, 181, 132, 17);
        btnIsIncludeAdditionalProperties.setText("是否包含附加属性");

        btnIsFormatDates = new Button(composite_1, SWT.CHECK);
        btnIsFormatDates.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                comboCustomDatePattern.setEnabled(btnIsFormatDates.getSelection());
            }
        });
        btnIsFormatDates.setSelection(true);
        btnIsFormatDates.setBounds(11, 204, 570, 17);
        btnIsFormatDates.setText("是否格式化Date,类型date的字段是生成@JsonFormat注解，默认值格式：yyyy-MM-dd");

        comboCustomDatePattern = new Combo(composite_1, SWT.NONE);
        comboCustomDatePattern.setItems(new String[]{"yyyy-MM-dd"});
        comboCustomDatePattern.setBounds(11, 227, 270, 25);
        comboCustomDatePattern.setText("yyyy-MM-dd");

        btnIsFormatDateTimes = new Button(composite_1, SWT.CHECK);
        btnIsFormatDateTimes.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                comboCustomDateTimePattern.setEnabled(btnIsFormatDateTimes.getSelection());
            }
        });
        btnIsFormatDateTimes.setSelection(true);
        btnIsFormatDateTimes.setBounds(11, 263, 723, 17);
        btnIsFormatDateTimes.setText("是否格式化DateTime，类型dateTime的字段是否生成@JsonFormat注解，默认值yyyy-MM-dd HH:mm:ss");

        comboCustomDateTimePattern = new Combo(composite_1, SWT.NONE);
        comboCustomDateTimePattern.setItems(new String[]{"yyyy-MM-dd HH:mm:ss"});
        comboCustomDateTimePattern.setBounds(11, 286, 270, 25);
        comboCustomDateTimePattern.setText("yyyy-MM-dd HH:mm:ss");

        Label lbltime = new Label(composite_1, SWT.NONE);
        lbltime.setBounds(11, 317, 293, 17);
        lbltime.setText("自定义的时间（Time）格式");

        comboCustomTimePattern = new Combo(composite_1, SWT.NONE);
        comboCustomTimePattern.setBounds(11, 340, 280, 25);

        textSourceFile = new Text(shell, SWT.BORDER);
        textSourceFile.setBounds(119, 66, 465, 23);

        Label lblNewLabel_1 = new Label(shell, SWT.NONE);
        lblNewLabel_1.setText("需要被转换的文档");
        lblNewLabel_1.setBounds(10, 66, 108, 17);

        Button btnSelectSourceFile = new Button(shell, SWT.NONE);
        btnSelectSourceFile.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                selectSourceFile();
            }
        });
        btnSelectSourceFile.setText("...");
        btnSelectSourceFile.setBounds(585, 64, 35, 27);

        button_Create = new Button(shell, SWT.NONE);
        button_Create.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                try {
                    createSourceCode();
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
            }
        });
        button_Create.setText("开始生成java原始文件");
        button_Create.setBounds(10, 623, 165, 27);

        button_Close = new Button(shell, SWT.NONE);
        button_Close.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                shell.dispose();
            }
        });
        button_Close.setText("关闭");
        button_Close.setBounds(289, 623, 80, 27);

        buttonRestoreDefaults = new Button(shell, SWT.NONE);
        buttonRestoreDefaults.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                setDefaults();
            }
        });
        buttonRestoreDefaults.setText("恢复默认值");
        buttonRestoreDefaults.setBounds(181, 623, 102, 27);

    }

    private void selectOutPutTargetDirectory() {
        String folder = MessageDialog.folderDialog(shell, null);
        if (folder == null) {
            return;
        }
        textOutPutTargetDirectory.setText(folder);
    }

    private void selectSourceFile() {
        String sourceFile = MessageDialog.fileDialog(shell, null, new String[]{"*.json", "*.yaml", "*.yml"}, false);
        if (sourceFile == null) {
            return;
        }
        textSourceFile.setText(sourceFile);
    }

    private void setDefaults() {
        textClassNamePrefix.setText("");
        textClassNameSuffix.setText("");
        btnIsUseTitleAsClassname.setSelection(false);
        btnIsIncludeEqualsAndHashCode.setSelection(true);
        btnIsIncludeNoArgsConstructor.setSelection(true);
        btnIsIncludeAllArgsConstructor.setSelection(true);
        btnIsIncludeBuilder.setSelection(true);

        btnIsIncludeAccessors.setSelection(false);
        btnAccessorsFluentValue.setSelection(false);
        btnAccessorsFluentValue.setEnabled(false);
        btnAccessorsChainValue.setSelection(false);
        btnAccessorsChainValue.setEnabled(false);
        lblAccessorsprefixGetter.setEnabled(false);
        textAccessorsPrefix.setText("");
        textAccessorsPrefix.setEnabled(false);

        btnIsEnumTypeAddSuffix.setSelection(false);
        btnIsEnumInSubPackage.setSelection(true);

        btnIsSerializable.setSelection(true);

        btnIsInitializeCollections.setSelection(false);
        btnIsUseInteger.setSelection(true);
        btnIsUseFloat.setSelection(true);
        btnIsIncludeValidationAnnotations.setSelection(true);
        btnIsFormatDates.setSelection(true);
        comboCustomDatePattern.setEnabled(btnIsFormatDates.getSelection());
        comboCustomDatePattern.setText("yyyy-MM-dd");
        btnIsFormatDateTimes.setSelection(true);
        comboCustomDateTimePattern.setEnabled(btnIsFormatDateTimes.getSelection());
        comboCustomDateTimePattern.setText("yyyy-MM-dd HH:mm:ss");
        comboCustomTimePattern.setText("");

    }

    private void setIncludeAccessorsEnabled() {
        boolean isIncludeAccessors = btnIsIncludeAccessors.getSelection();
        btnAccessorsFluentValue.setEnabled(isIncludeAccessors);
        btnAccessorsChainValue.setEnabled(isIncludeAccessors);
        lblAccessorsprefixGetter.setEnabled(isIncludeAccessors);
        textAccessorsPrefix.setEnabled(isIncludeAccessors);
    }

    public void createSourceCode() throws IOException {
        try {
            verifyInput();
        } catch (Exception e) {
            MessageDialog.openError(shell, "错误", e.getMessage());
            return;
        }
        GenerationConfig config = new GenerationConfig() {

            @Override
            public boolean isIncludeEqualsAndHashCode() {
                return btnIsIncludeEqualsAndHashCode.getSelection();
            }

            @Override
            public boolean isIncludeNoArgsConstructor() {
                return btnIsIncludeNoArgsConstructor.getSelection();
            }

            @Override
            public boolean isIncludeAllArgsConstructor() {
                return btnIsIncludeAllArgsConstructor.getSelection();
            }

            @Override
            public boolean isIncludeBuilder() {
                return btnIsIncludeBuilder.getSelection();
            }

            @Override
            public boolean isFieldNameConstants() {
                return btnIsIncludeFieldNameConstants.getSelection();
            }

            @Override
            public boolean isIncludeAccessors() {
                return btnIsIncludeAccessors.getSelection();
            }

            @Override
            public boolean getAccessorsFluentValue() {
                return btnAccessorsFluentValue.getSelection();
            }

            @Override
            public boolean getAccessorsChainValue() {
                return btnAccessorsFluentValue.getSelection();
            }

            @Override
            public String getAccessorsPrefix() {
                return textAccessorsPrefix.getText();
            }

            @Override
            public boolean isEnumIncludeGetter() {
                return btnIsEnumIncludeGetter.getSelection();
            }

            @Override
            public boolean isEnumIncludeAllArgsConstructor() {
                return btnIsEnumIncludeAllArgsConstructor.getSelection();
            }

            /**
             * 获取属性词分隔符
             * @return 一个空数组（即没有单词分隔符）
             */
            @Override
            public char[] getPropertyWordDelimiters() {
                return new char[]{'-', ' ', '_'};
            }

            /**
             * 是否使用长整数
             * @return <code>false</code>
             */
            @Override
            public boolean isUseLongIntegers() {
                return btnIsUseLongIntegers.getSelection();
            }

            /**
             * 是否使用双精度数字
             * @return <code>true</code>
             */
            @Override
            public boolean isUseDoubleNumbers() {
                return btnIsUseDoubleNumbers.getSelection();
            }

            /**
             * 是否使用标题作为类名
             * @return {@code false}
             */
            @Override
            public boolean isUseTitleAsClassname() {
                return btnIsUseTitleAsClassname.getSelection();
            }

            /**
             * 是否包含Jsr303注解
             * @return <code>false</code>
             */
            @Override
            public boolean isIncludeValidationAnnotations() {
                return btnIsIncludeValidationAnnotations.getSelection();
            }

            /**
             * 获得源类型
             * @return {@link SourceType#JSONSCHEMA}
             */
            @Override
            public SourceType getSourceType() {
                return SourceType.JSONSCHEMA;
            }

            /**
             * 是否使用可序列化
             * @return <code>false</code>
             */
            @Override
            public boolean isSerializable() {
                return btnIsSerializable.getSelection();
            }

            /**
             * 是否初始化集合
             * @return <code>true</code>
             */
            @Override
            public boolean isInitializeCollections() {
                return btnIsInitializeCollections.getSelection();
            }

            /**
             * 类名前缀
             * @return
             */
            @Override
            public String getClassNamePrefix() {
                return textClassNamePrefix.getText();
            }

            /**
             * 类名后缀
             * @return
             */
            @Override
            public String getClassNameSuffix() {
                return textClassNameSuffix.getText();
            }

            /**
             * 文件扩展名
             * @return
             */
            @Override
            public String[] getFileExtensions() {
                return new String[]{};
            }

            /**
             * 是否使用大整数
             *
             * @return <code>false</code>
             */
            @Override
            public boolean isUseBigIntegers() {
                return btnIsUseBigIntegers.getSelection();
            }

            /**
             * 是否使用大的小数
             * @return <code>false</code>
             */
            @Override
            public boolean isUseBigDecimals() {
                return btnIsUseBigDecimals.getSelection();
            }

            /**
             * 是否包含附加属性
             * @return <code>true</code>
             */
            @Override
            public boolean isIncludeAdditionalProperties() {
                return btnIsIncludeAdditionalProperties.getSelection();
            }

            /**
             * Java目标版本
             * @return 当前JVM版本
             */
            @Override
            public String getTargetVersion() {
                return JavaVersion.parse(System.getProperty("java.version"));
            }


            /**
             * 是否格式化日期时间
             * @return <code>false</code>
             */
            @Override
            public boolean isFormatDateTimes() {
                return btnIsFormatDateTimes.getSelection();
            }

            /**
             * 是否格式化日期
             * @return <code>false</code>
             */
            @Override
            public boolean isFormatDates() {
                return btnIsFormatDates.getSelection();
            }

            /**
             * 引用片段路径分隔符
             * @return "#/."
             */
            @Override
            public String getRefFragmentPathDelimiters() {
                return "#/.";
            }

            /**
             * 自定义日期schema
             * @return
             */
            @Override
            public String getCustomDatePattern() {
                return comboCustomDatePattern.getText();
            }

            /**
             * 自定义时间schema
             * @return
             */
            @Override
            public String getCustomTimePattern() {
                return comboCustomTimePattern.getText();
            }

            /**
             * 自定义日期时间schema
             * @return
             */
            @Override
            public String getCustomDateTimePattern() {
                return comboCustomDateTimePattern.getText();
            }


            /**
             * 是否使用JakartaValidation
             * @return {@code false}
             */
            @Override
            public boolean isUseJakartaValidation() {
                return true;
            }

            @Override
            public boolean isEnumInSubPackage() {
                return btnIsEnumInSubPackage.getSelection();
            }

            @Override
            public boolean isEnumTypeAddSuffix() {
                return btnIsEnumTypeAddSuffix.getSelection();
            }

        };
        saveConfig();
        URL source = URLUtil.fileUrl(textSourceFile.getText());
        File outPutTargetDirectory = new File(textOutPutTargetDirectory.getText());
        JsonSchema2LombokPojo.generate(config, source, true,
                outPutTargetDirectory, textTargetPackage.getText(), StandardCharsets.UTF_8.toString());
        Desktop.getDesktop().open(outPutTargetDirectory);
    }

    private void verifyInput() {
        Assert.isFalse(StrUtil.isBlank(textTargetPackage.getText()), "请输入包名称");
        Assert.isFalse(StrUtil.isBlank(textSourceFile.getText()), "请输入源文件");
        Assert.isFalse(StrUtil.isBlank(textOutPutTargetDirectory.getText()), "请输入输出文件夹");
    }

    private void saveConfig() {
        ConfigUtil configUtil = new ConfigUtil();
        configUtil.setValue("targetPackage", textTargetPackage.getText());
        configUtil.setValue("sourceFile", textSourceFile.getText());
        configUtil.setValue("outPutTargetDirectory", textOutPutTargetDirectory.getText());

        configUtil.setValue("classNamePrefix", textClassNamePrefix.getText());
        configUtil.setValue("classNameSuffix", textClassNameSuffix.getText());
        configUtil.setValue("isUseTitleAsClassname", btnIsUseTitleAsClassname.getSelection());
        configUtil.setValue("isIncludeEqualsAndHashCode", btnIsIncludeEqualsAndHashCode.getSelection());
        configUtil.setValue("isIncludeNoArgsConstructor", btnIsIncludeNoArgsConstructor.getSelection());
        configUtil.setValue("isIncludeAllArgsConstructor", btnIsIncludeAllArgsConstructor.getSelection());
        configUtil.setValue("isIncludeBuilder", btnIsIncludeBuilder.getSelection());
        configUtil.setValue("isIncludeAccessors", btnIsIncludeAccessors.getSelection());
        configUtil.setValue("accessorsFluentValue", btnAccessorsFluentValue.getSelection());
        configUtil.setValue("accessorsChainValue", btnAccessorsChainValue.getSelection());
        configUtil.setValue("accessorsPrefix", textAccessorsPrefix.getText());
        configUtil.setValue("isEnumIncludeGetter", btnIsEnumIncludeGetter.getSelection());
        configUtil.setValue("isEnumIncludeAllArgsConstructor", btnIsEnumIncludeAllArgsConstructor.getSelection());
        configUtil.setValue("isEnumTypeAddSuffix", btnIsEnumTypeAddSuffix.getSelection());
        configUtil.setValue("isEnumInSubPackage", btnIsEnumInSubPackage.getSelection());

        configUtil.setValue("isSerializable", btnIsSerializable.getSelection());
        configUtil.setValue("isInitializeCollections", btnIsInitializeCollections.getSelection());
        configUtil.setValue("isUseFloat", btnIsUseFloat.getSelection());
        configUtil.setValue("isUseDoubleNumbers", btnIsUseDoubleNumbers.getSelection());
        configUtil.setValue("isUseBigDecimals", btnIsUseBigDecimals.getSelection());
        configUtil.setValue("isUseInteger", btnIsUseInteger.getSelection());
        configUtil.setValue("isUseLongIntegers", btnIsUseLongIntegers.getSelection());
        configUtil.setValue("isUseBigIntegers", btnIsUseBigIntegers.getSelection());

        configUtil.setValue("btnIsIncludeValidationAnnotations", btnIsIncludeValidationAnnotations.getSelection());
        configUtil.setValue("btnIsFormatDates", btnIsFormatDates.getSelection());
        configUtil.setValue("comboCustomDatePattern", comboCustomDatePattern.getText());
        configUtil.setValue("btnIsFormatDateTimes", btnIsFormatDateTimes.getSelection());
        configUtil.setValue("customDateTimePattern", comboCustomDateTimePattern.getText());
        configUtil.setValue("customTimePattern", comboCustomTimePattern.getText());

        configUtil.setValue("configSaved", true);
    }


    private void loadLastUserConfig() {
        ConfigUtil configUtil = new ConfigUtil();
        if (!configUtil.existFile()) {
            return;
        }
        if (!configUtil.getBool("configSaved")) {
            return;
        }
        textTargetPackage.setText(configUtil.getValue("targetPackage", ""));
        textSourceFile.setText(configUtil.getValue("sourceFile", ""));
        textOutPutTargetDirectory.setText(configUtil.getValue("outPutTargetDirectory", ""));

        textClassNamePrefix.setText(configUtil.getValue("classNamePrefix", ""));
        textClassNameSuffix.setText(configUtil.getValue("classNameSuffix", ""));

        btnIsUseTitleAsClassname.setSelection(configUtil.getBool("isUseTitleAsClassname"));
        btnIsIncludeEqualsAndHashCode.setSelection(configUtil.getBool("isIncludeEqualsAndHashCode"));
        btnIsIncludeNoArgsConstructor.setSelection(configUtil.getBool("isIncludeNoArgsConstructor"));
        btnIsIncludeAllArgsConstructor.setSelection(configUtil.getBool("isIncludeAllArgsConstructor"));
        btnIsIncludeBuilder.setSelection(configUtil.getBool("isIncludeBuilder"));
        btnIsIncludeAccessors.setSelection(configUtil.getBool("isIncludeAccessors"));
        btnAccessorsFluentValue.setSelection(configUtil.getBool("accessorsFluentValue"));
        btnAccessorsChainValue.setSelection(configUtil.getBool("accessorsChainValue"));
        textAccessorsPrefix.setText(configUtil.getValue("accessorsPrefix", ""));
        btnIsEnumIncludeGetter.setSelection(configUtil.getBool("isEnumIncludeGetter"));
        btnIsEnumIncludeAllArgsConstructor.setSelection(configUtil.getBool("isEnumIncludeAllArgsConstructor"));
        btnIsEnumTypeAddSuffix.setSelection(configUtil.getBool("isEnumTypeAddSuffix"));
        btnIsEnumInSubPackage.setSelection(configUtil.getBool("isEnumInSubPackage"));

        btnIsSerializable.setSelection(configUtil.getBool("isSerializable"));
        btnIsInitializeCollections.setSelection(configUtil.getBool("isInitializeCollections"));
        btnIsUseFloat.setSelection(configUtil.getBool("isUseFloat"));
        btnIsUseDoubleNumbers.setSelection(configUtil.getBool("isUseDoubleNumbers"));
        btnIsUseBigDecimals.setSelection(configUtil.getBool("isUseBigDecimals"));
        btnIsUseInteger.setSelection(configUtil.getBool("isUseInteger"));
        btnIsUseLongIntegers.setSelection(configUtil.getBool("isUseLongIntegers"));
        btnIsUseBigIntegers.setSelection(configUtil.getBool("isUseBigIntegers"));

        btnIsIncludeValidationAnnotations.setSelection(configUtil.getBool("btnIsIncludeValidationAnnotations"));
        btnIsFormatDates.setSelection(configUtil.getBool("btnIsFormatDates"));
        comboCustomDatePattern.setText(configUtil.getValue("comboCustomDatePattern", ""));
        btnIsFormatDateTimes.setSelection(configUtil.getBool("btnIsFormatDateTimes"));
        comboCustomDateTimePattern.setText(configUtil.getValue("customDateTimePattern", ""));
        comboCustomTimePattern.setText(configUtil.getValue("customTimePattern", ""));

        setIncludeAccessorsEnabled();
        comboCustomDatePattern.setEnabled(btnIsFormatDates.getSelection());
        comboCustomDateTimePattern.setEnabled(btnIsFormatDateTimes.getSelection());
    }

}
